//
//  SKLViewController.m
//  tucici
//
//  Created by tucici on 2017/11/26.
//  Copyright © 2017年 tucici. All rights reserved.
//

#import "SKLViewController.h"
@interface SKLViewController ()<YJDNaviBarDelegate>
@property (nonatomic, strong) YJDHud *hud;
@end

@implementation SKLViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.alphaView.hidden = NO;
    
    // Do any additional setup after loading the view.
}

- (YJDHud *)hud
{
    if (!_hud)
    {
        _hud = [YJDHud yjd_hud];
        _hud.color = BLUE_COLOR;
        UIWindow *window = [UIApplication sharedApplication].delegate.window;
        [window addSubview:_hud];
        [_hud mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            make.center.equalTo(window);
            make.size.mas_equalTo(_hud.bounds.size);
        }];
        //        NSLayoutConstraint *centerX = [NSLayoutConstraint constraintWithItem:_hud attribute:NSLayoutAttributeCenterX
        //                                                                   relatedBy:NSLayoutRelationEqual toItem:self.view
        //                                                                   attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];
        //
        //        NSLayoutConstraint *centerY = [NSLayoutConstraint constraintWithItem:_hud attribute:NSLayoutAttributeCenterY
        //                                                                   relatedBy:NSLayoutRelationEqual toItem:self.view
        //                                                                   attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0];
        //
        //            NSLayoutConstraint *width = [NSLayoutConstraint constraintWithItem:_hud attribute:NSLayoutAttributeWidth
        //                                                                     relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil
        //                                                                     attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:_hud.bounds.size.width];
        //
        //            NSLayoutConstraint *height = [NSLayoutConstraint constraintWithItem:_hud attribute:NSLayoutAttributeHeight
        //                                                                      relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil
        //                                                                      attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:_hud.bounds.size.height];
        //        [self.view addConstraints:@[centerX,centerY,width,height]];
    }
    return _hud;
}

- (UIView *)alphaView
{
    if (!_alphaView)
    {
        _alphaView = [[UIView alloc]init];
        _alphaView.backgroundColor = [UIColor blackColor];
        _alphaView.alpha = 0.3;
        [self.view addSubview:_alphaView];
        [_alphaView mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsZero);
        }];
    }
    return _alphaView;
}

- (YJDNaviBar *)naviBar
{
    if (!_naviBar)
    {
        _naviBar = [[YJDNaviBar alloc] init];
        _naviBar.delegate = self;
        [self.view addSubview:_naviBar];
        [_naviBar mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            make.left.equalTo(self.view);
            make.right.equalTo(self.view);
            make.top.equalTo(self.view);
            make.height.mas_equalTo(BUTTONHEIGHT);
        }];
    }
    return _naviBar;
}

- (void)yjd_startHUDDDD
{
    [self.view bringSubviewToFront:self.hud];
    [self.hud yjd_startHud];
}

- (void)yjd_stopHUDDDDD
{
    [self.hud yjd_stopHud];
}

- (void)yjd_show
{
    UIWindow *window =  [UIApplication sharedApplication].delegate.window;
    self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    //必须判断presentedViewController 是nil，否则报错
    if (window.rootViewController.presentedViewController)
    {
        DeLog(@"当前窗口没有退出 %@",window.rootViewController.presentedViewController);
        [window.rootViewController presentViewController:self animated:YES completion:nil];
    }
    else
    {
        [window.rootViewController presentViewController:self animated:YES completion:nil];
    }
}

+ (void)yjd_show
{
    SKLViewController *vc = [[self alloc] init];
    UIWindow *window =  [UIApplication sharedApplication].delegate.window;
    vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    if (window.rootViewController.presentedViewController)
    {
        DeLog(@"当前窗口没有退出 %@",window.rootViewController.presentedViewController);
    }
    else
    {
        [window.rootViewController presentViewController:vc animated:YES completion:nil];
    }
}

- (void)yjd_methodForNaviBarDelegate
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (BOOL)prefersStatusBarHidden {
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc
{
    DeLog(@"dealloc~~~~~~~~~");
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
